<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
  <title>扫码抽奖</title>
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
  <style>
    body {
      margin: 0;
      font-family: Arial, sans-serif;
      background: linear-gradient(to bottom, #ffecd2, #fcb69f);
      height: 100vh;
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
    }

    .title {
      font-size: 24px;
      margin-bottom: 20px;
      color: #fff;
    }

    .wheel-container {
      position: relative;
      width: 300px;
      height: 300px;
      border-radius: 50%;
      background: #fff;
      box-shadow: 0 0 10px rgba(0,0,0,0.2);
    }

    .wheel {
      width: 100%;
      height: 100%;
      border-radius: 50%;
      background: conic-gradient(
        #f00 0deg 60deg,
        #0f0 60deg 120deg,
        #00f 120deg 180deg,
        #ff0 180deg 240deg,
        #f0f 240deg 300deg,
        #0ff 300deg 360deg
      );
      transition: transform 3s ease-out;
      transform: rotate(0deg);
    }

    .pointer {
      position: absolute;
      top: -10px;
      left: 50%;
      transform: translateX(-50%);
      width: 0;
      height: 0;
      border-left: 10px solid transparent;
      border-right: 10px solid transparent;
      border-bottom: 30px solid #000;
    }

    .btn {
      margin-top: 30px;
      padding: 10px 30px;
      font-size: 18px;
      background: #ff6f00;
      color: #fff;
      border: none;
      border-radius: 30px;
      cursor: pointer;
    }

    .btn:disabled {
      background: #ccc;
      cursor: not-allowed;
    }

    .result {
      margin-top: 20px;
      font-size: 18px;
      color: #fff;
    }
  </style>
</head>
<body>

  <div class="title">🎉 扫码抽奖活动</div>

  <div class="wheel-container">
    <div class="wheel" id="wheel"></div>
    <div class="pointer"></div>
  </div>

  <button class="btn" id="drawBtn">开始抽奖</button>

  <div class="result" id="result"></div>

  <script>
    // 奖项配置
    const prizes = [
      { name: '一等奖', probability: 1 },
      { name: '二等奖', probability: 5 },
      { name: '三等奖', probability: 10 },
      { name: '谢谢参与', probability: 84 }
    ];

    const wheel = document.getElementById('wheel');
    const drawBtn = document.getElementById('drawBtn');
    const resultDiv = document.getElementById('result');

    // 抽奖逻辑
    function draw() {
      const rand = Math.random() * 100;
      let sum = 0;
      let selected = prizes[prizes.length - 1];

      for (const prize of prizes) {
        sum += prize.probability;
        if (rand < sum) {
          selected = prize;
          break;
        }
      }

      // 计算旋转角度（360度/6项 = 60度/项）
      const index = prizes.findIndex(p => p.name === selected.name);
      const baseDegree = 360 * 5; // 多转几圈
      const prizeDegree = 360 - (index * 60) - 30; // 停在中间
      const finalDegree = baseDegree + prizeDegree;

      wheel.style.transform = `rotate(${finalDegree}deg)`;

      // 记录结果
      const record = {
        prize: selected.name,
        time: new Date().toLocaleString()
      };
      const history = JSON.parse(localStorage.getItem('lotteryHistory') || '[]');
      history.unshift(record);
      localStorage.setItem('lotteryHistory', JSON.stringify(history.slice(0, 10)));

      setTimeout(() => {
        alert(`恭喜获得：${selected.name}`);
        drawBtn.disabled = false;
      }, 3000);
    }

    drawBtn.addEventListener('click', () => {
      drawBtn.disabled = true;
      draw();
    });
  </script>

</body>
</html>